<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="<c:url value="/jslib/jquery-3.4.1.min.js"/>"></script>

<title>客户显示</title>
</head>
<body>
	<div style="width:80%;margin:0 auto;text-align:center">
		<table width="100%">
		<tr>
			<th>姓名</th>
			<th>性别</th>
			<th>生日</th>
			<th>电话</th>
			<th>邮箱</th>
			<th>说明</th>
			<th colspan=2>操作</th>
		</tr>
		<c:forEach items="${requestScope.pb.beanList }" var="customer" begin="0">
			<tr>
				<td>${customer.cname}</td>
				<td>${customer.gender}</td>
				<td>${customer.birthday}</td>
				<td>${customer.cellphone}</td>
				<td>${customer.email}</td>
				<td>${customer.description}</td>
				<td><a href="<c:url value="/CustomerServlet?method=preEdit&cid=${customer.cid }"/>">编辑</a></td>
				<td><a href="<c:url value="/CustomerServlet?method=delete&cid=${customer.cid }"/>">删除</a></td>
			</tr>
		</c:forEach>
		
		<c:if test="${fn:length(requestScope.pb.beanList) == 0}">
			<tr>
			 	<td colspan=7>
			 		么有数据！
			 	</td>
			</tr>
		</c:if>
	</table>
	</div>
</br>
<center>
	第${pb.pc}页/共${pb.tp}页
	<a href="${pb.url }&pc=1"/>首页</a>
	<c:if test="${pb.pc > 1}">
		<a href="${pb.url }&pc=${pb.pc - 1}"/>上一页</a>
	</c:if>
	
	<c:choose>
		<%--  如果总页数不足10页，把所有的页数也显示出来 --%>
		<c:when test="${pb.tp <= 10 }">
			<c:set var="begin" value="1"></c:set>
			<c:set var="end" value="${pb.tp}"></c:set>
		</c:when>
		<%--  如果总页数不足10页，通过公式计算--%>
		<c:otherwise>
			<c:set var="begin" value="${pb.pc - 5}"></c:set>
			<c:set var="end" value="${pb.pc + 4}"></c:set>
			<%--  头溢出 --%>

			<c:if test="${begin < 1}">
				<c:set var="begin" value="1"></c:set>
				<c:set var="end" value="10"></c:set>
			</c:if>
			<%--  尾溢出 --%>
			<c:if test="${end > pb.tp}">
				<c:set var="begin" value="${pb.tp - 9}"></c:set>
				<c:set var="end" value="${pb.tp }"></c:set>
			</c:if>
		</c:otherwise>
	</c:choose>

	<c:forEach var="i" begin="${begin }" end="${end }">
		<c:choose>
			<c:when test="${pb.pc eq i }">
				[${i }]
			</c:when>
			<c:otherwise>
				<a href="${pb.url }&pc=${i}"/>[${i }]</a>
			</c:otherwise>
		</c:choose>
	</c:forEach>
	<c:if test="${pb.pc < pb.tp}">
		<a href="${pb.url }&pc=${pb.pc + 1}"/>下一页</a>
	</c:if>
	<a href="${pb.url }&pc=${pb.tp}"/>尾页</a>
</center>

</body>
</html>